<?php
namespace app\api\controller\v1;
use app\api\controller\Common;

class Favorites extends Common{
	var $modelDb;
	public function _initialize(){
		parent::_initialize();
		$this->modelDb = model("Favorites");
	}
	public function add(){
		if ($this->postData['typeid'] == 1 && $this->postData['contentid'] == $this->uinfo['id']) {
			return $this->app_error('自己不能关注自己');
		}
		$this->postData['userid'] = $this->uinfo['id'];
		//判断是否已收藏
		if (!isset($this->postData['notcheck'])) { 
			$result = $this->validate($this->postData, 'Favorites.check_contentid');
			if ($result !== true) {
				return $this->app_error($result);
			}
		}
		$favs = $this->modelDb->save_datas($this->postData);
		if ($favs !== '') {
			return $this->app_success(['favs'=>$favs]);
		}else{
			return $this->app_error($this->modelDb->getError());
		}
	}
}